<style>
.lease-container{
	display: flex;
	flex: 1;
	width: 750upx;
}
.lease-list{
	display: flex;
	flex-direction: column;
	width: 750upx;
}
.uni-list-cell:after {
    position: absolute;
    z-index: 3;
    right: 0;
    bottom: 0;
    left: 0;
}
.lease-btn{
	font-size: 30upx;
}
.uni-media-list{
	align-items: center;	
}
</style>

<template>
	<view class="lease-container">
		<view class="lease-list">
			
			<!-- 轮播图 -->
			<swiper class="swiper" v-if="bannerList.length>0" :indicator-dots="true" :circular="true" :autoplay="true" :interval="4000" :duration="200">
				<swiper-item class="swiper-img" v-for="(item,index) in bannerList" :key="index">
					<view  class="swiper-item"  @click="toUrl(item)">
						<image :src="item.img"></image>
					</view>
				</swiper-item>
			</swiper>
			
			<view class="uni-list">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in list" :key="index">
					<view class="uni-media-list uni-list-cell-navigate uni-navigate-right" @click="toLeaseDetail(item)">
						<image class="uni-media-list-logo" :src="item.pic"></image>
						<view class="uni-media-list-body">
							<!-- <view class="uni-media-list-text-top">{{item.rname}}
							  <text>({{item.status }})</text>
							</view> -->
							<view class="uni-media-list-text-top">{{item.name}}</view>
							<view class="uni-media-list-text-bottom uni-ellipsis">{{item.content}}</view>
							<!-- <view class="uni-media-list-text-bottom uni-ellipsis">{{item.bname}}</view>
							<view class="uni-media-list-text-bottom uni-ellipsis">{{item.addr}}</view> -->
							<view class="sell-num">
								<text class="fl">¥{{item.price}}元/小时  (需押金:{{item.deposit}}元)</text>
								<!-- <text class="fl">(需押金:{{item.deposit}}元)</text> -->
								<!-- <text class="fr">已租30</text> -->
							</view>
						</view>
						<!-- <view class="lease-btn-box">
							<button type="primary" class="lease-btn" @click="toPay(item)">我要租</button>
						</view> -->
					</view>
				</view>
			</view>
			<view v-if="list.length==0" class="nodata">
				<image src="../../../static/img/nodata.png" mode=""></image>
			</view>
			<div class="nomore" v-if="!hasMore">没有更多了</div>
		</view>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				hasMore:true,
				pageNum:1,
				pageSize:20,
				list:[
// 					{
// 						img:'https://img.yzcdn.cn/2.jpg',
// 						title:'超威电池',
// 						content:'石家庄棉六店',
// 						discount:'¥20'
// 					}
				],
				bannerList:[]
			};
		},
		computed:{
			...mapState(['userInfo'])
		},
		methods:{
			toLeaseDetail(item){
				uni.navigateTo({
					url:'leaseDetail/leaseDetail?item='+JSON.stringify(item)
				})
			},
			toInfo(item){
			   uni.navigateTo({
				url:'leaseInfo/leaseInfo?item='+JSON.stringify(item)
			   })
			},
			toUrl(item){
				if(item.type == 3){
					uni.navigateTo({
						url:'../storeList/storeDetail/storeDetail?bid='+item.busId
					})
				}else if(item.type == 4){
					uni.navigateTo({
						url:'../shop/shopGoods/shopGoods?gid='+item.busId
					})
				}else if(item.type == 0){
					plus.runtime.openURL(item.busId)
				}
			},
			getLeaseList(flag) {
				let that = this
				uni.request({
					url: this.httpUrl + 'leaseRes/list4Page',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						pageNum: that.pageNum,
						pageSize: that.pageSize
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == 1) {
							if(flag){
								that.list = res.data.data.data
							}else{
								that.list.push(...res.data.data.data)
							}
							that.list.forEach(item=>{
								switch (item.status){
									case 0:
									    item.status = '下架'
									case 1:
									    item.status = '可用'
									case 2:
									    item.status = '在租'		
										break;
									default:
										break;
								}
							})
							if(res.data.data.data.length < that.pageSize){
								that.hasMore = false
							}else{
								that.hasMore = true
								that.pageNum ++
							}
							
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								mask: true
							})
						}
					}
				})
			},
			toPay(item){
			   // this.payShow = true
			   let uid = this.userInfo.uid
			   let bid = item.bid
			   let did = item.lid
			   console.log(this.userInfo);
			   // return
			   uni.request({
					url: this.httpUrl + 'resLease/lease',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						uid: uid,
						did: did,
						bid:bid
					},
					success: (res) => {
						// console.log(res)
						if (res.data.code == 1) {
							uni.showToast({
								title: '申请成功，请等待审核',
								icon: 'none',
								mask: true
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								mask: true
							})
						}
					}
			   })
			},
			getBanner(){
				let that = this
				uni.request({
					url: this.httpUrl + 'banner/listByCondition',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						module: 2
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == 1) {
							that.bannerList = res.data.data
							// that.goodsList.push(...res.data.data.data)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								mask: true
							})
						}
					}
				})
			},
		},
		onReachBottom(){
		  if(this.hasMore){
			  this.getLeaseList()
		  }
		},
		onPullDownRefresh() {
			this.pageNum = 1
			this.getLeaseList(true)
			this.getBanner()
			uni.stopPullDownRefresh();
		},
		mounted() {
			this.getLeaseList(false)
			this.getBanner()
		}
	}
</script>
